package com.cskaoyan._03api;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/21 15:23
 **/
/*
线程的优先级1-10
创建并启动2个线程 A  B
A线程设置最大优先级10

B线程设置最小优先级 1

每个线程打印10个数
 */
public class Demo3 {
    public static void main(String[] args) {
        // 创建线程对象并启动
        MyThread3 t1 = new MyThread3();
        MyThread3 t2 = new MyThread3();

        t1.setName("A");
        t2.setName("B");


        // setPriority(int n)设置线程优先级
        t1.setPriority(Thread.MAX_PRIORITY);

        t2.setPriority(Thread.MIN_PRIORITY);

        //getPriority() 获取线程优先级
        //int priority = t1.getPriority();
        //System.out.println(priority);

        t1.start();
        t2.start();
    }
}

class MyThread3 extends Thread{
    // run
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(getName()+"----"+i);
        }
    }
}